# Copyright (c) 2017 Presto Labs Pte. Ltd.
# Author: inkyu, xguo

import json
import logging
import os

from coin2.support.product_info.spot_huobi_v1 import convert_coin1_constants


pi_file = 'data/coin2/product_info/old_compat/huobi.json'
with open(pi_file) as f:
  static_constants = convert_coin1_constants(json.load(f)['product_infos'])
coin_only_exchange = True
active_base_currency_list = [
    'ADA',
    'BCH',
    'BSV',
    'BTC',
    'BAND',
    'BTM',
    'COMP',
    'DASH',
    "DOT",
    'ELF',
    'EOS',
    'ETC',
    'ETH',
    'FIL',
    'HT',
    'JST',
    'KNC',
    'KSM',
    'LINK',
    'LTC',
    'NEO',
    'OMG',
    'ONT',
    'PAI',
    'QTUM',
    'SRM',
    'STEEM',
    'TNB',
    'TRX',
    'VEN',
    'UNI',
    'WAX',
    'XLM',
    'XRP',
    'YFI',
    'ZEC',
]


dynamic_constants = {}
if int(os.getenv('USE_DYNAMIC_SYMBOL', 0)):
  try:
    from coin2.support.product_info.spot_huobi_v1 import gen_coin1_constants
    dynamic_constants = gen_coin1_constants()
  except Exception as e:
    logging.error('Failed to use huobi dynamic symbols! %s', e)


quote_currency_list = list(set(
    static_constants.get('quote_currency_list', []) +
    dynamic_constants.get('quote_currency_list', [])))
currency_list = list(set(
    ['USD', 'YFV'] +
    static_constants.get('currency_list', []) +
    dynamic_constants.get('currency_list', [])))
symbol_list = list(set(
    static_constants.get('symbol_list', []) +
    dynamic_constants.get('symbol_list', [])))


def gen_active_symbol_list():
  res = []
  for base_currency in active_base_currency_list:
    for quote_currency in ['USDT', 'BTC']:
      symbol = '%s%s' % (base_currency.lower(), quote_currency.lower())
      symbol3s = '%s3s%s' % (base_currency.lower(), quote_currency.lower())
      symbol3l = '%s3l%s' % (base_currency.lower(), quote_currency.lower())
      for each_symbol in [symbol, symbol3s, symbol3l]:
        if each_symbol in symbol_list:
          res.append(each_symbol)
  return res


active_symbol_list = gen_active_symbol_list()
